/**
 * 
 */
package com.conan.zone.system.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import com.conan.zone.exception.SystemException;
import com.conan.zone.framework.service.impl.AbstractServiceImpl;
import com.conan.zone.system.exception.LoginValidateErrorException;
import com.conan.zone.system.model.User;
import com.conan.zone.system.service.ILoginService;
import com.conan.zone.system.service.IUserService;

/**
 * @author Conan
 *
 */
@Service
public class LoginServiceImpl extends AbstractServiceImpl<User> implements ILoginService {
	

	@Resource
	@Qualifier("userServiceImpl")
	private IUserService userService;
	
	@Override
	public User userLogin(User user) {
		try{
			user.setPassword(DigestUtils.md5Hex(user.getPassword()));
			List<User> userList = userService.all(user);
			if(userList!=null && userList.size()<=0){
				throw new LoginValidateErrorException("无效的用户名或密码!");
			}
			return userList.get(0);
		}catch(LoginValidateErrorException e){
			throw e;
		}catch(Exception e){
			throw new SystemException(e);
		}
	}

}
